package bTree.LeetCode;

public class 一个小组的最大实力值 {
    public long maxStrength(int[] nums) {
        int length = nums.length;
        long result = nums[0];
        long[] maxDp = new long[length];
        long[] minDp = new long[length];
        maxDp[0] = nums[0];
        minDp[0] = nums[0];
        for (int i = 1; i < length; i++) {
            maxDp[i] = nums[i];
            minDp[i] = nums[i];
            for (int j = 0; j < i; j++) {
                long a = maxDp[j] * nums[i];
                long b = minDp[j] * nums[i];
                long max = Math.max(a, b);
                long min = Math.min(a, b);
                //比较每一轮的
                maxDp[i] = Math.max(maxDp[i], max);
                minDp[i] = Math.min(minDp[i], min);
            }
            result = Math.max(result, maxDp[i]);
        }
        return result;
    }
}